import Api from './api';

let API;
const METHODS = ['$catch', '$on', '$once', '$off'];
export default API = {
    install(Vue, options) {
        let api = new Api(options);
        try { 
            Vue.prototype.$api = api;
        } catch (_) {
            Vue.config.globalProperties.$api = api;
        }
        METHODS.forEach(key => {
            this[key] = api[key].bind(api);
        });
        this.$api = api;
    },
};
